<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script>
        function f1(){
            //创建对象方式一
            var obj=new Object();
            obj.name="abc";
            obj.age=21;
            obj.play=function(){
                alert(this.name+"正在玩");
            };


            console.log(obj.name);
            var fieldName="name";
            console.log(obj[fieldName]);
            console.log(obj["age"]);
            obj.play();
        }


        function f2(){
            //创建对象方式二
            var p=new Person("aaa",23);

            console.log(p.name);
            p.play();

        }

        function Person(name,age){
            this.name=name;
            this.age=age;
            this.play=function(){
                alert(this.name+"正在玩");
            };
        }



        function f3(){
            //创建对象方式三
            var p={
                "name":"bbb",
                "age":22,
                "play":function(){
                    alert(this.name+"正在玩");
                }
            };


            console.log(p.name);
            p.play();

        }

        function f4(){
            //创建对象方式四
            var s="{'name':'ccc','age':33}";

            var obj=eval("("+s+")");

            console.log(obj.name)
        }

    </script>





</head>
<body onload="f4();">
</body>
</html>